package data

import (
	"math/rand"
	"time"
)

// NewLoop
//---------------------------
// 启动一个线程，定时执行某个函数
// ---------------------------
func NewLoop(intervalTime int, fn func(), isInit bool) {
	rand.Seed(time.Now().UnixNano())
	seed := rand.Intn(10)
	if isInit {
		fn()
	}
	go func() {
		dur := intervalTime + seed
		for range time.Tick(time.Duration(dur) * time.Second) {
			fn()
		}
	}()
}
